package com.cy.pj.eiems.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.eiems.Exception.ServiceException;
import com.cy.pj.eiems.dao.AgencyCommentDao;
import com.cy.pj.eiems.entity.AgencyInformation;
import com.cy.pj.eiems.service.EiemsAgencyComment;
import com.cy.pj.eiems.vo.PageObject;

@Service
public class EiemsAgencyCommentimpl implements EiemsAgencyComment{
	
	@Autowired
	private AgencyCommentDao agencyCommentDao;

	@Override
	public PageObject<AgencyInformation> findObjects(String name,Integer pageCurrent) {
		if(pageCurrent == null || pageCurrent <1) throw new IllegalArgumentException("当前无页码");
		int rowCount = agencyCommentDao.getRowCount(name);
		if(rowCount == 0) throw new ServiceException("所访问记录不存在...");
		int pageSize = 5;
		int startIndex = (pageCurrent -1)* pageSize;
		List<AgencyInformation> records = agencyCommentDao.findObjects(name, startIndex, pageSize);
		PageObject<AgencyInformation> pageObjct = new PageObject<>(pageCurrent, pageSize, rowCount, records);
		pageObjct.setPageCount(pageCurrent);
		pageObjct.setPageSize(pageSize);
		pageObjct.setRowCount(rowCount);
		pageObjct.setRecords(records);
		pageObjct.setPageCount((rowCount-1)/pageSize+1);
		return pageObjct;
	}
	
}
